#include "Timestamp.h"


Timestamp::Timestamp():microSecondsSinceEpoch_(0) {}

Timestamp::Timestamp(int64_t microSecondsSinceEpoch)
    : microSecondsSinceEpoch_(microSecondsSinceEpoch)
    {}

Timestamp Timestamp:: now()
{
    return Timestamp(time(NULL));
    
}

std::string Timestamp::toString() const
{
    char buf[100]={0};
    time_t time_sec = microSecondsSinceEpoch_+8*3600; // 转换成东八区 北京时间
    tm* tm_time=localtime(&time_sec);
    snprintf(buf,100,"%4d/%02d/%02d %02d:%02d:%02d",
    tm_time->tm_year+1900,
    tm_time->tm_mon+1,
    tm_time->tm_mday,
    tm_time->tm_hour,
    tm_time->tm_min,
    tm_time->tm_sec);

    return buf;
}

